unit Class_MOBL_STAF;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TMOBLSTAF=class(TUniEngine)
  private
    FUNITLINK: string;
    FSTAFIDEX: Integer;
    FSTAFKJND: Integer;
    FSTAFKJQJ: Integer;
    FSTAFBDID: Integer;
    FSTAFCODE: string;
    FSTAFWORK: string;
    FDEPTLINK: string;
    FRECTLINK: string;
    FSTAFMEMO: string;
    FDEPTNAME: string;
    FRECTNAME: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property UNITLINK: string read FUNITLINK write FUNITLINK;
    property STAFIDEX: Integer read FSTAFIDEX write FSTAFIDEX;
    property STAFKJND: Integer read FSTAFKJND write FSTAFKJND;
    property STAFKJQJ: Integer read FSTAFKJQJ write FSTAFKJQJ;
    property STAFBDID: Integer read FSTAFBDID write FSTAFBDID;
    property STAFCODE: string read FSTAFCODE write FSTAFCODE;
    property STAFWORK: string read FSTAFWORK write FSTAFWORK;
    property DEPTLINK: string read FDEPTLINK write FDEPTLINK;
    property RECTLINK: string read FRECTLINK write FRECTLINK;
    property STAFMEMO: string read FSTAFMEMO write FSTAFMEMO;
    property DEPTNAME: string read FDEPTNAME write FDEPTNAME;
    property RECTNAME: string read FRECTNAME write FRECTNAME;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AMOBLSTAF:TMOBLSTAF):TMOBLSTAF;overload;        
    class procedure CopyIt(AMOBLSTAF:TMOBLSTAF;var Result:TMOBLSTAF);overload;

    class function  ExpSQL(AStafIdex:string):string;    
  end;

implementation

{ TMOBLSTAF }
procedure TMOBLSTAF.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('STAF_IDEX').Value := STAFIDEX;
        ParamByName('STAF_KJND').Value := STAFKJND;
        ParamByName('STAF_KJQJ').Value := STAFKJQJ;
        ParamByName('STAF_BDID').Value := STAFBDID;
        ParamByName('STAF_CODE').Value := STAFCODE;
        ParamByName('STAF_WORK').Value := STAFWORK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
        ParamByName('RECT_LINK').Value := RECTLINK;
        ParamByName('STAF_MEMO').Value := STAFMEMO;
        ParamByName('DEPT_NAME').Value := DEPTNAME;
        ParamByName('RECT_NAME').Value := RECTNAME; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('STAF_IDEX').Value := STAFIDEX;
        ParamByName('STAF_KJND').Value := STAFKJND;
        ParamByName('STAF_KJQJ').Value := STAFKJQJ;
        ParamByName('STAF_BDID').Value := STAFBDID;
        ParamByName('STAF_CODE').Value := STAFCODE;
        ParamByName('STAF_WORK').Value := STAFWORK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
        ParamByName('RECT_LINK').Value := RECTLINK;
        ParamByName('STAF_MEMO').Value := STAFMEMO;
        ParamByName('DEPT_NAME').Value := DEPTNAME;
        ParamByName('RECT_NAME').Value := RECTNAME; 
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('STAF_IDEX').Value := STAFIDEX;
        ParamByName('STAF_BDID').Value := STAFBDID;
 
      end;  
    end;
  end;
end;

function TMOBLSTAF.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_MOBL_STAF',['UNIT_LINK',UNITLINK,'STAF_IDEX',STAFIDEX,'STAF_BDID',STAFBDID],AUniConnection);
end;

function TMOBLSTAF.GetNextIdex: Integer;
begin

end;

function TMOBLSTAF.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TMOBLSTAF.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_MOBL_STAF WHERE   UNIT_LINK=:UNIT_LINK AND STAF_IDEX=:STAF_IDEX AND STAF_BDID=:STAF_BDID';
end;

function TMOBLSTAF.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_MOBL_STAF'
         +'    ( UNIT_LINK, STAF_IDEX, STAF_KJND, STAF_KJQJ, STAF_BDID'
         +'    , STAF_CODE, STAF_WORK, DEPT_LINK, RECT_LINK, STAF_MEMO'
         +'    , DEPT_NAME, RECT_NAME)'
         +'    VALUES'
         +'    (:UNIT_LINK,:STAF_IDEX,:STAF_KJND,:STAF_KJQJ,:STAF_BDID'
         +'    ,:STAF_CODE,:STAF_WORK,:DEPT_LINK,:RECT_LINK,:STAF_MEMO'
         +'    ,:DEPT_NAME,:RECT_NAME)';
end;

function TMOBLSTAF.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D',[UNITLINK,STAFIDEX,STAFBDID]);
end;

function TMOBLSTAF.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_MOBL_STAF SET'
         +'    STAF_KJND=:STAF_KJND,'
         +'    STAF_KJQJ=:STAF_KJQJ,'
         +'    STAF_CODE=:STAF_CODE,'
         +'    STAF_WORK=:STAF_WORK,'
         +'    DEPT_LINK=:DEPT_LINK,'
         +'    RECT_LINK=:RECT_LINK,'
         +'    STAF_MEMO=:STAF_MEMO,'
         +'    DEPT_NAME=:DEPT_NAME,'
         +'    RECT_NAME=:RECT_NAME'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   STAF_IDEX=:STAF_IDEX'
         +'    AND   STAF_BDID=:STAF_BDID';
end;

constructor TMOBLSTAF.Create;
begin

end;

destructor TMOBLSTAF.Destroy;
begin

  inherited;
end;

class function TMOBLSTAF.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TMOBLSTAF.Create;
  with TMOBLSTAF(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    STAFIDEX:=AUniQuery.FieldByName('STAF_IDEX').AsInteger;
    STAFKJND:=AUniQuery.FieldByName('STAF_KJND').AsInteger;
    STAFKJQJ:=AUniQuery.FieldByName('STAF_KJQJ').AsInteger;
    STAFBDID:=AUniQuery.FieldByName('STAF_BDID').AsInteger;
    STAFCODE:=AUniQuery.FieldByName('STAF_CODE').AsString;
    STAFWORK:=AUniQuery.FieldByName('STAF_WORK').AsString;
    DEPTLINK:=AUniQuery.FieldByName('DEPT_LINK').AsString;
    RECTLINK:=AUniQuery.FieldByName('RECT_LINK').AsString;
    STAFMEMO:=AUniQuery.FieldByName('STAF_MEMO').AsString;
    DEPTNAME:=AUniQuery.FieldByName('DEPT_NAME').AsString;
    RECTNAME:=AUniQuery.FieldByName('RECT_NAME').AsString;
  end;  
end;

class procedure TMOBLSTAF.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TMOBLSTAF(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    STAFIDEX:=AUniQuery.FieldByName('STAF_IDEX').AsInteger;
    STAFKJND:=AUniQuery.FieldByName('STAF_KJND').AsInteger;
    STAFKJQJ:=AUniQuery.FieldByName('STAF_KJQJ').AsInteger;
    STAFBDID:=AUniQuery.FieldByName('STAF_BDID').AsInteger;
    STAFCODE:=AUniQuery.FieldByName('STAF_CODE').AsString;
    STAFWORK:=AUniQuery.FieldByName('STAF_WORK').AsString;
    DEPTLINK:=AUniQuery.FieldByName('DEPT_LINK').AsString;
    RECTLINK:=AUniQuery.FieldByName('RECT_LINK').AsString;
    STAFMEMO:=AUniQuery.FieldByName('STAF_MEMO').AsString;
    DEPTNAME:=AUniQuery.FieldByName('DEPT_NAME').AsString;
    RECTNAME:=AUniQuery.FieldByName('RECT_NAME').AsString;
  end;  
end;

class function  TMOBLSTAF.CopyIt(AMOBLSTAF: TMOBLSTAF): TMOBLSTAF;
begin
  Result:=TMOBLSTAF.Create;
  TMOBLSTAF.CopyIt(AMOBLSTAF,Result)
end;

class procedure TMOBLSTAF.CopyIt(AMOBLSTAF:TMOBLSTAF;var Result:TMOBLSTAF);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=AMOBLSTAF.UNITLINK;
  Result.STAFIDEX:=AMOBLSTAF.STAFIDEX;
  Result.STAFKJND:=AMOBLSTAF.STAFKJND;
  Result.STAFKJQJ:=AMOBLSTAF.STAFKJQJ;
  Result.STAFBDID:=AMOBLSTAF.STAFBDID;
  Result.STAFCODE:=AMOBLSTAF.STAFCODE;
  Result.STAFWORK:=AMOBLSTAF.STAFWORK;
  Result.DEPTLINK:=AMOBLSTAF.DEPTLINK;
  Result.RECTLINK:=AMOBLSTAF.RECTLINK;
  Result.STAFMEMO:=AMOBLSTAF.STAFMEMO;
  Result.DEPTNAME:=AMOBLSTAF.DEPTNAME;
  Result.RECTNAME:=AMOBLSTAF.RECTNAME;
end;

class function TMOBLSTAF.ExpSQL(AStafIdex: string): string;
begin
  Result:='SELECT A.UNIT_LINK,A.STAF_IDEX,A.STAF_BDID,A.STAF_KJND,A.STAF_KJQJ,A.STAF_CODE,A.STAF_WORK,A.DEPT_LINK,A.RECT_LINK,A.STAF_MEMO,'
         +'    B.DEPT_NAME AS DEPT_NAME,C.DEPT_NAME AS RECT_NAME'
         +'    FROM TBL_STAF A'
         +'    LEFT JOIN TBL_DEPT B ON A.DEPT_LINK=B.DEPT_LINK'
         +'    LEFT JOIN TBL_RECT C ON A.RECT_LINK=C.DEPT_LINK'
         +'    WHERE A.STAF_IDEX=%S ORDER BY A.KJND_KJQJ DESC';
  Result:=Format(Result,[QuotedStr(AStafIdex)]);
end;

end.

